@echo off
echo 正在测试Rust Nacos服务器的HTTP API兼容性...
echo.

REM 检查curl是否可用
curl --version >nul 2>&1
if errorlevel 1 (
    echo 错误：curl未安装，请先安装curl
    pause
    exit /b 1
)

echo ✅ curl已安装

REM 测试服务器是否运行
echo 🔍 检查服务器状态...
curl -s http://localhost:8848/health >nul
if errorlevel 1 (
    echo ❌ 服务器未运行或无法连接
    echo 请先启动Rust Nacos服务器
    pause
    exit /b 1
)

echo ✅ 服务器运行正常

echo.
echo 🧪 开始HTTP API兼容性测试...
echo.

REM 测试1: 健康检查
echo 1. 测试健康检查API... >> test_results.txt
curl -s http://localhost:8848/health >> test_results.txt 2>&1
echo.

REM 测试2: 注册服务实例
echo 2. 测试注册服务实例... >> test_results.txt
curl -s -X POST http://localhost:8848/nacos/v1/ns/instance \
  -H "Content-Type: application/json" \
  -d "{\"namespace\":\"public\",\"service_name\":\"test-service\",\"ip\":\"127.0.0.1\",\"port\":8080,\"weight\":1.0,\"healthy\":true,\"enabled\":true,\"ephemeral\":true}" \
  >> test_results.txt 2>&1
echo.

REM 测试3: 获取服务实例
echo 3. 测试获取服务实例... >> test_results.txt
curl -s "http://localhost:8848/nacos/v1/ns/instance/list?namespace=public&service_name=test-service" >> test_results.txt 2>&1
echo.

REM 测试4: 发布配置
echo 4. 测试发布配置... >> test_results.txt
curl -s -X POST http://localhost:8848/nacos/v1/cs/configs \
  -H "Content-Type: application/json" \
  -d "{\"namespace\":\"public\",\"group\":\"DEFAULT_GROUP\",\"data_id\":\"test-config\",\"content\":\"test-content\"}" \
  >> test_results.txt 2>&1
echo.

REM 测试5: 获取配置
echo 5. 测试获取配置... >> test_results.txt
curl -s "http://localhost:8848/nacos/v1/cs/configs?namespace=public&group=DEFAULT_GROUP&data_id=test-config" >> test_results.txt 2>&1
echo.

REM 测试6: 删除配置
echo 6. 测试删除配置... >> test_results.txt
curl -s -X DELETE http://localhost:8848/nacos/v1/cs/configs \
  -H "Content-Type: application/json" \
  -d "{\"namespace\":\"public\",\"group\":\"DEFAULT_GROUP\",\"data_id\":\"test-config\"}" \
  >> test_results.txt 2>&1
echo.

REM 测试7: 注销服务实例
echo 7. 测试注销服务实例... >> test_results.txt
curl -s -X DELETE http://localhost:8848/nacos/v1/ns/instance \
  -H "Content-Type: application/json" \
  -d "{\"namespace\":\"public\",\"service_name\":\"test-service\",\"ip\":\"127.0.0.1\",\"port\":8080}" \
  >> test_results.txt 2>&1
echo.

echo.
echo 📊 测试结果汇总:
echo =========================
type test_results.txt
echo.
echo 🧪 兼容性测试完成！
echo 详细结果已保存到: test_results.txt
pause